#include<iostream>
using namespace std;
const int N = 1e6 + 10;
char s[N];
int ne[N];
int n;
int main()
{
	int t = 1;
	while (scanf("%d", &n), n) {
		scanf("%s", s + 1);
		for (int i = 2, j = 0; i <= n; i++) {
			while (j && s[i] != s[j + 1])j = ne[j];
			if (s[i] == s[j + 1])j++;
			ne[i] = j;
		}
		printf("Test case #%d\n", t++);
		for (int i = 1; i <= n; i++) {
			int k = i - ne[i];
			if (i % k == 0 && i / k > 1) {
				cout << i << " " << i / k << endl;
			}
		}
		puts("");
	}
	return 0;
}